/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.gr.context;
import com.gr.search.Connector;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Hieudt
 */
public class History {
    private int userID;
    private String termList;
    private String URLs;
    
    public History(int id, String tl, String url){  
        userID = id;
        this.termList = tl;
        this.URLs = url;
    }
     public History(int id, String tl){  
        userID = id;
        this.termList = tl;
    }
    public String historyToString(){
        StringBuffer buf = new StringBuffer();
        buf.append(userID).append(" ").append(termList).append(URLs);
        return buf.toString();
    }
    public void writeHistory(){
        try
        {
            Connection con = Connector.connect2();
            java.sql.PreparedStatement stmt=con.prepareStatement("INSERT INTO history(user_id,term_list) VALUES(?, ?);");
            stmt.setInt(1,userID);
            stmt.setString(2,termList);
            //stmt.setString(3,URLs);
            stmt.executeUpdate();
            con.close();
        }
        catch (ClassNotFoundException ex) {
            Logger.getLogger(History.class.getName()).log(Level.SEVERE, null, ex);
        }catch(SQLException e)
        {
            System.err.println("Cant write history!!!");
        }
    }
}
